package com.hmall.api.client.fallback;

import com.hmall.api.client.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.context.annotation.Bean;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Slf4j
public class ItemClietnFallbackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("item-service服务调用失败", cause);
                return List.of();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                log.error("item-service服务调用失败", cause);
                throw new RuntimeException("item-service服务调用失败");
            }

            @Override
            public void recoverStock(Map<Long, Integer> itemNumMap) {
                log.error("item-service服务调用失败", cause);
                throw new RuntimeException("item-service服务调用失败");
            }
        };
    }


}
